import { FormProps, FormSchema } from '/@/components/Table';

import { BasicColumn } from '/@/components/Table/src/types/table';
import { Tag } from 'ant-design-vue';
import { h } from 'vue';

//表格显示列
export function getBasicColumns(): BasicColumn[] {
  // @ts-ignore
  return [
    {
      title: '分类名称',
      dataIndex: 'name',
      width: 100,
    },
    {
      title: '上级分类',
      dataIndex: 'parentName',
      width: 150,
    },
    {
      title: '上级分类id',
      dataIndex: 'parentId',
      width: 150,
      defaultHidden: true,
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 150,
      customRender: ({ record }) => {
        let status = record.status;
        let color = '';
        switch (status) {
          case 'NORMAL':
            status = '正常';
            color = 'green';
            break;
          case 'LOCKED':
            status = '锁定';
            color = 'purple';
            break;
        }
        return h(Tag, { color: color }, () => status);
      },
    },
    {
      title: '序列',
      dataIndex: 'indexOrder',
      width: 150,
    },
  ];
}

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 150,
    baseColProps: { lg: 6, md: 24 },
    schemas: formParamSchema,
  };
}

//查询条件表单
export const formParamSchema: FormSchema[] = [
  /*  {
      field: 'name',
      label: '租户名称',
      component: 'Input',
    },*/
];

//编辑表单
export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '分类名称',
    component: 'Input',
    required: false,
  },
  {
    field: 'indexOrder',
    label: '序列',
    component: 'Input',
    required: true,
  },

  {
    field: 'parentId',
    label: '上级分类id',
    component: 'TreeSelect',
    required: false,
    componentProps: {
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
  },
];
